
cmake_minimum_required(VERSION 3.4.1)

project("paperless_sdk_so")

include_directories(include/)
add_definitions(-D_LINUX -D_ANDROID -DDEVICETYPE=0)

# 设置IS_ARMEABI_V7A变量，默认false，非armeabi-v7a架构
set(IS_ARMEABI_V7A FALSE)
# MATCHES 判断字符串是否相等（忽略大小写）
if ("${ANDROID_ABI}" MATCHES "armeabi-v7a")
    set(IS_ARMEABI_V7A TRUE)
endif()

message("========= CMakeLists ${PROJECT_NAME}: ANDROID_ABI:${ANDROID_ABI} =========")
message("========= CMakeLists ${PROJECT_NAME}: CMAKE_ANDROID_ARCH_ABI:${CMAKE_ANDROID_ARCH_ABI} =========")
message("========= CMakeLists ${PROJECT_NAME}: CMAKE_SOURCE_DIR:${CMAKE_SOURCE_DIR}/../nativeLibs/${ANDROID_ABI}/ =========")
message("========= CMakeLists ${PROJECT_NAME}: IS_ARMEABI_V7A:${IS_ARMEABI_V7A} =========")

add_library(
        native-lib
        SHARED
        jni_wallet_netinit.cpp
        wallet_net.cpp
        helpers.c
)

# 导入预编译的库
# add_library(<name> [STATIC | SHARED | MODULE | OBJECT] <source1> <source2> ...)
set(soList "avcodec-57" "avdevice-57" "avfilter-6" "avformat-57" "avutil-55" "Codec" "ExecProc" "meetcoreAnd" "NetClient" "Device-OpenSles" "PBmeetcoreAnd" "postproc-54" "meetAnd" "swresample-2" "swscale-4" "SDL2" "main")
foreach (lib_name ${soList})
    message("========= CMakeLists ${PROJECT_NAME}: add_library:${lib_name} =========")
    add_library(${lib_name} SHARED IMPORTED)
    set_target_properties(${lib_name} PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../nativeLibs/${ANDROID_ABI}/lib${lib_name}.so)
endforeach ()

add_library(z STATIC IMPORTED)
set_target_properties(z PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../nativeLibs/${ANDROID_ABI}/libz.a)

find_library(log-lib log )
find_library(opensles-lib OpenSLES )
# target_link_libraries(<target> [item1 [item2 [...]]])
# <target>: 目标名称，即您要链接的可执行文件或库
# [item1 [item2 [...]]]: 要链接到目标的库或接口库。
target_link_libraries(
        native-lib
        avcodec-57
        avdevice-57
        avfilter-6
        avformat-57
        avutil-55
        postproc-54
        swresample-2
        swscale-4
        SDL2
        main
        NetClient
        Device-OpenSles
        Codec
        ExecProc
        meetcoreAnd
        PBmeetcoreAnd
        meetAnd
        z
        ${log-lib}
        ${opensles-lib})

## 只在匹配armeabi-v7a时链接libSDL2和libmain
#if(${IS_ARMEABI_V7A})
#    message("========= CMakeLists target_link_libraries:SDL2 and main =========")
#    target_link_libraries(native-lib SDL2 main)
#else()
#    message("========= CMakeLists skip target_link_libraries:SDL2 and main =========")
#endif()

